package com.yanxu.proxy.proxy_static;

import com.yanxu.proxy.base.IOrderService;
import com.yanxu.proxy.base.Order;
import com.yanxu.proxy.base.OrderServiceImpl;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2025/4/15-2025
 * @Description: OrderService 进行静态代理
 */
public class OrderServiceStaticProxy {
    //注入目标对象
    private IOrderService orderService;


    public int saveOrder(Order order) {
        //前置增强
        beforeMethod(order);

        orderService=new OrderServiceImpl();
        int i = orderService.saveOrder(order);

        //后置增强
        afterMethod();
        return i;
    }

    public void beforeMethod(Order order) {
        System.out.println("静态代理beforeMethod");
        Integer userId = order.getUserId();
        int num = userId % 2;
        System.out.println("静态代理分配到db【"+num+"】 处理数据!");
    }

    public void afterMethod() {
        System.out.println("静态代理afterMethod");
    }

}